home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / pd / utilities / tinymeter / source / tinymeter_main / handler.c < prev    next >
C/C++ Source or Header  |  1996-05-20  |  24KB  |  801 lines

  1. #include <intuition/classusr.h>
  2. #include <intuition/gadgetclass.h>
  3. #include <intuition/cghooks.h>
  4. #include <intuition/icclass.h>
  5. #include <intuition/classes.h>
  6. #include <utility/tagitem.h>
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <dos/dos.h>
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <dos/notify.h>
  13. #include <intuition/intuition.h>
  14. #include <libraries/SysInfo.h>
  15. #include <utility/tagitem.h>
  16. #include <clib/macros.h>
  17. #include <libraries/commodities.h>
  18. #include <libraries/ScreenNotify.h>
  19. #include <datatypes/datatypesclass.h>
  20. #include <datatypes/datatypes.h>
  21. #include <datatypes/pictureclass.h>
  22. #include <workbench/workbench.h>
  23. #include <workbench/startup.h>
  24. #include "gaugeclass.h"
  25. #include "launchclass.h"
  26. #include "tinymeter.h"
  27.  
  28. #define test_test       0
  29. #define test_getwin     1
  30.  
  31. #define do_clock        1
  32. #define do_mem          2
  33. #define do_vol          3
  34.  
  35. struct TestMessage
  36. {
  37.     struct  Message ts_Message;
  38.     ULONG   MethodID;
  39.     struct  tm_sys_set  *set;
  40.     struct  tm_gau_set  *list;
  41.     ULONG   posx,
  42.         posy,
  43.         sizx;
  44. };
  45.  
  46. init_time_request(struct timerequest *my_time_request_clock, ULONG my_time_mask_clock)
  47. {
  48.     ULONG interval;
  49.     my_time_request_clock -> tr_node.io_Command     = TR_GETSYSTIME;
  50.     DoIO(my_time_request_clock);
  51.     interval=my_time_request_clock -> tr_time.tv_secs;
  52.     my_time_request_clock -> tr_node.io_Command     = TR_ADDREQUEST;
  53.     my_time_request_clock -> tr_time.tv_secs        = interval+1;
  54.     my_time_request_clock -> tr_time.tv_micro       = NULL;
  55.     SetSignal(NULL,my_time_mask_clock);
  56.     SendIO(my_time_request_clock);
  57. }
  58.  
  59. ULONG snapSub(struct tm_sys_set *set, struct tm_data *data)
  60. {
  61.     struct lau_enty         *list;
  62.     int                     i;
  63.     struct IntuiMessage     *m;
  64.  
  65.     while((m=(struct IntuiMessage *)GetMsg( data->win->UserPort )))ReplyMsg( m );
  66.     data->win=(struct Window *) snapBackground(set,data);
  67.                 drawBackground(set,data);
  68.     for(i=NULL;i<data->num_of_gaug;i++)
  69.     {
  70.     if(data->gdg[i])
  71.     {
  72.         GetAttr(LAU_List,data->gdg[i],&list);
  73.         if(list) AddGList(data->win,data->gdg[i],0,1,NULL);
  74.         else     AddGList(data->win,data->gdg[i],-1,1,NULL);
  75.         SetAttrs(data->gdg[i],GA_Width, data->gauge_x_size, NULL);
  76.     }
  77.     }
  78.     RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  79.     return(1L << data->win->UserPort->mp_SigBit);
  80. }
  81.  
  82. setBase(struct tm_data *data)
  83. {
  84.     struct tm_gau_set   *many;
  85.     int                 i;
  86.     ULONG               cur;
  87.     for(i=NULL,many=data->list;i<data->num_of_gaug;i++,many=many->next)
  88.     {
  89.     if(data->gdg[i])
  90.     {
  91.         GetAttr(GAU_Current,data->gdg[i],&cur);
  92.         SetAttrs(data->gdg[i],GAU_Current,cur,GAU_Base,cur,TAG_DONE);
  93.     }
  94.     }
  95.     RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  96. }
  97.  
  98. handle_launcher(struct tm_data *data, UWORD ID, struct Gadget *obj,struct WBArg *wbarg, ULONG numarg)
  99. {
  100.     struct  Window          *lwin;
  101.     struct  RastPort        *rp,
  102.                 tmpras;
  103.     BOOL                    foo=TRUE,
  104.                 start=FALSE;
  105.     struct  lau_entry       *entry,
  106.                 *foobar;
  107.     LONG                    dummy,
  108.                 height,
  109.                 width;
  110.     LONG                    x,
  111.                 y,
  112.                 selected,
  113.                 sigs,
  114.                 lastsel;
  115.     ULONG                   pen_bg,
  116.                 pen_bright,
  117.                 pen_dark,
  118.                 pen_cur,
  119.                 pen_entry,
  120.                 window_mask,
  121.                 lwindow_mask,
  122.                 down,trans;
  123.     UWORD                   entryheight,
  124.                 iw=NULL,
  125.                 y_pos;
  126.     struct IntuiMessage     *m;
  127.     struct BitMapHeader     *bmhd;
  128.     struct MsgPort          *appport;
  129.     struct AppWindow        *appwin;
  130.     ULONG                    appwinsig;
  131.  
  132.     GetAttr(LAU_ColEntry     ,obj,&pen_entry);
  133.     GetAttr(LAU_ColBrightEdg ,obj,&pen_bright);
  134.     GetAttr(LAU_ColDarkEdg   ,obj,&pen_dark);
  135.     GetAttr(LAU_ColBackground,obj,&pen_bg);
  136.     GetAttr(LAU_ColCursor    ,obj,&pen_cur);
  137.     GetAttr(LAU_List         ,obj,&entry);
  138.     GetAttr(LAU_Down         ,obj,&down);
  139.     GetAttr(LAU_Transparent  ,obj,&trans);
  140.     if(foobar=entry)
  141.     {
  142.     InitRastPort(&tmpras);
  143.     SetFont(&tmpras,data->Font[ID]);
  144.     dummy=NULL;
  145.     entryheight=data->Font[ID]->tf_YSize;
  146.     width=data->gdg[ID]->Width+2;
  147.     do
  148.     {
  149.         if(foobar->img)
  150.         {
  151.         GetDTAttrs(foobar->img,PDTA_BitMapHeader,&bmhd,TAG_DONE);
  152.         if(bmhd)
  153.         {
  154.             entryheight=MAX(entryheight,bmhd->bmh_Height+2);
  155.             iw=MAX(iw,bmhd->bmh_Width+6);
  156.         }
  157.         }
  158.         foobar->width=TextLength(&tmpras,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  159.         width=MAX(width,foobar->width+12+iw);
  160.         dummy++;
  161.     }
  162.     while(foobar=foobar->next);
  163.  
  164.     y_pos=((entryheight-((data->Font[ID]->tf_Baseline+data->Font[ID]->tf_YSize)>>1))>>1);
  165.     if(data->Font[ID]->tf_Baseline<data->Font[ID]->tf_YSize)
  166.     {
  167.         y_pos+=data->Font[ID]->tf_Baseline-1;
  168.         if(y_pos<data->Font[ID]->tf_Baseline)y_pos=data->Font[ID]->tf_Baseline;
  169.     }
  170.     else
  171.     {
  172.         y_pos+=data->Font[ID]->tf_YSize-1;
  173.         if(y_pos<data->Font[ID]->tf_YSize)   y_pos=data->Font[ID]->tf_YSize;
  174.     }
  175.  
  176.     height=(entryheight*dummy)+2;
  177.     y=data->gdg[ID]->TopEdge+data->win->TopEdge-( down==lau_up ? height : ( down== lau_down ? -data->gdg[ID]->Height : height>>1 ));
  178.     if((lwin=(struct Window *)OpenWindowTags(NULL,
  179.         WA_Left,            data->gdg[ID]->LeftEdge+data->win->LeftEdge-1,
  180.         WA_Top,             y,
  181.         WA_Width,           width,
  182.         WA_Height,          height,
  183.         WA_Flags,           WFLG_BORDERLESS|WFLG_REPORTMOUSE|WFLG_RMBTRAP|WFLG_ACTIVATE,
  184.         WA_PubScreen,       data->scr,
  185.         WA_IDCMP,           IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE,
  186.         TAG_END)))
  187.     {
  188.         if(appport=(struct MsgPort *)CreateMsgPort(0L))
  189.         {
  190.         appwin=(struct AppWindow *)AddAppWindow(0L, 0L, lwin, appport , 0L);
  191.         appwinsig= 1L << appport->mp_SigBit;
  192.         }
  193.         selected     =-1;
  194.         lastsel      =-1;
  195.         window_mask  = 1L << data->win->UserPort->mp_SigBit;
  196.         lwindow_mask = 1L << lwin->UserPort->mp_SigBit;
  197.  
  198.         SetFont(rp=lwin->RPort,data->Font[ID]);
  199.         SetAPen(rp,pen_bg); RectFill(rp,0,0,width-1,height-1);
  200.         draw_border_new(rp,0,0,width,height,pen_bright,pen_dark);
  201.         SetAPen(rp,pen_entry);
  202.         SetDrMd(rp,JAM1);
  203.         foobar=entry;
  204.         dummy=0;
  205.         do
  206.         {
  207.         if(foobar->img)
  208.         {
  209.             GetDTAttrs(foobar->img,PDTA_BitMapHeader,&bmhd,TAG_DONE);
  210.             DrawDTObject(foobar->img,0,0,rp,2+((iw-bmhd->bmh_Width)>>1),(dummy*entryheight)+1+((entryheight-bmhd->bmh_Height)>>1),-1,-1,trans);
  211.         }
  212.         Move(rp,iw+7,((dummy++)*entryheight)+y_pos+1);
  213.         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  214.         }
  215.         while(foobar=foobar->next);
  216.         while(foo)
  217.         {
  218.         sigs=Wait( window_mask | lwindow_mask | appwinsig );
  219.         if(sigs & appwinsig)
  220.         {
  221.             struct AppMessage *apm;
  222.             while(apm=(struct AppMessage *)GetMsg(appport))
  223.             {
  224.             selected=(apm->am_MouseY-1)/entryheight;
  225.             for(foobar=entry,dummy=0;dummy<selected;dummy++)foobar=foobar->next;
  226.             if(apm->am_Type==AMTYPE_APPWINDOW)
  227.             {
  228.                 RunFile(foobar,data,apm->am_ArgList,apm->am_NumArgs);
  229.             }
  230.             ReplyMsg(apm);
  231.             }
  232.         }
  233.         if(sigs & window_mask)
  234.         {
  235.             while(m=(struct IntuiMessage *)GetMsg(data->win->UserPort))
  236.             {
  237.             switch (m->Class)
  238.             {
  239.                 case    IDCMP_GADGETDOWN:
  240.                     foo=FALSE;
  241.                     break;
  242.             }
  243.             ReplyMsg(m);
  244.             }
  245.         }
  246.         if(sigs & lwindow_mask)
  247.         {
  248.             while(m=(struct IntuiMessage *)GetMsg(lwin->UserPort))
  249.             {
  250.             switch (m->Class)
  251.             {
  252.                 case    IDCMP_MOUSEBUTTONS:
  253.                     if((m->Code&15)==8)
  254.                     {
  255.                     selected=(m->MouseY-1)/entryheight;
  256.                     foo=FALSE;
  257.                     start=TRUE;
  258.                     }
  259.                     break;
  260.                 case    IDCMP_MOUSEMOVE:
  261.                     x=m->MouseX;
  262.                     y=m->MouseY;
  263.                     if((x>0)&&(y>0)&&(x<(width-1))&&(y<(height-1)))
  264.                     {
  265.                     selected=(y-1)/entryheight;
  266.                     if(selected!=lastsel)
  267.                     {
  268.                         if(lastsel!=-1)
  269.                         {
  270.                         SetAPen(rp,pen_bg);
  271.                         RectFill(rp,iw+3,1+(lastsel*entryheight),width-4,((lastsel+1)*entryheight));
  272.                         SetAPen(rp,pen_entry);
  273.                         for(foobar=entry,dummy=0;dummy<lastsel;dummy++)foobar=foobar->next;
  274.                         Move(rp,iw+7,(lastsel*entryheight)+y_pos+1);
  275.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  276.                         }
  277.                         SetAPen(rp,pen_cur);
  278.                         RectFill(rp,iw+3,1+(selected*entryheight),width-4,((selected+1)*entryheight));
  279.                         SetAPen(rp,pen_entry);
  280.                         for(foobar=entry,dummy=0;dummy<selected;dummy++)foobar=foobar->next;
  281.                         Move(rp,iw+7,(selected*entryheight)+y_pos+1);
  282.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  283.                     }
  284.                     lastsel=selected;
  285.                     }
  286.                     else
  287.                     {
  288.                     if(lastsel!=-1)
  289.                     {
  290.                         SetAPen(rp,pen_bg);
  291.                         RectFill(rp,iw+1,1+(lastsel*entryheight),width-2,((lastsel+1)*entryheight));
  292.                         SetAPen(rp,pen_entry);
  293.                         for(foobar=entry,dummy=0;dummy<lastsel;dummy++)foobar=foobar->next;
  294.                         Move(rp,iw+7,(lastsel*entryheight)+y_pos+1);
  295.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  296.                     }
  297.                     selected=-1;
  298.                     lastsel=-1;
  299.                     }
  300.                     break;
  301.             }
  302.             ReplyMsg(m);
  303.             }
  304.         }
  305.         }
  306.         while(m=(struct IntuiMessage *)GetMsg(data->win->UserPort))ReplyMsg(m);
  307.         while(m=(struct IntuiMessage *)GetMsg(lwin->UserPort))     ReplyMsg(m);
  308.  
  309.         if(appwin)  RemoveAppWindow(appwin);
  310.         if(appport) DeletePort(appport);
  311.  
  312.         CloseWindow(lwin);
  313.         if(start&&(selected>-1))
  314.         {
  315.         for(foobar=entry,dummy=0;dummy<selected;dummy++)foobar=foobar->next;
  316.         RunFile(foobar,data,wbarg,numarg);
  317.         }
  318.     }
  319.     else DisplayBeep(0);
  320.     }
  321. }
  322.  
  323. struct tm_sys_set *handler(struct tm_sys_set *set, struct tm_data *data, struct MsgPort *broker_mp, CxObj *broker, ULONG cxsigflag, Class *gclass, Class *lclass)
  324. {
  325.     BOOL                        running = TRUE;
  326.  
  327.     ULONG                       mem_val=0,
  328.                 vol_val=0,
  329.                 sigs,
  330.                 window_mask,
  331.                 my_time_mask_clock,
  332.                 my_test_port_mask,
  333.                 my_noti_port_mask=0L,
  334.                 my_app_port_mask =0L,
  335.                 my_handler;
  336.  
  337.     struct MsgPort             *my_time_port_clock,
  338.                    *my_test_port,
  339.                    *my_noti_port;
  340.  
  341.     struct timerequest         *my_time_request_clock;
  342.  
  343.     struct NotifyRequest       *notifyrequest;
  344.     LONG                        not_sig;
  345.     BOOL                        closed=FALSE;
  346.  
  347.     struct IntuiMessage        *m;
  348.     int                         i;
  349.     struct TestMessage         *test_msg;
  350.     struct tm_gau_set          *many,*next;
  351.     BOOL                        first_run=TRUE;
  352.     UWORD                       do_what;
  353.  
  354.     if(data->scrnot)
  355.     {
  356.     my_noti_port        = (struct MsgPort *)CreateMsgPort();
  357.     my_handler          = ((!data->on_public)|(!strcmp(&set->pub_name[0],"Workbench"))) ? (ULONG)AddWorkbenchClient(my_noti_port,0) : (ULONG)AddCloseScreenClient(data->scr,my_noti_port,0);
  358.     my_noti_port_mask   = 1L << my_noti_port->mp_SigBit;
  359.     }
  360.  
  361.     if(data->appwin) my_app_port_mask    = 1L << data->appport->mp_SigBit;
  362.  
  363.     window_mask  = 1L << data->win->UserPort->mp_SigBit;
  364.  
  365.     if(my_test_port=(struct MsgPort *)CreatePort("TinyMeter",0))
  366.     {
  367.     my_test_port_mask = 1L << (my_test_port->mp_SigBit);
  368.     if(my_time_port_clock=(struct MsgPort *)CreateMsgPort())
  369.     {
  370.         my_time_mask_clock    = 1L << (my_time_port_clock->mp_SigBit);
  371.         if(my_time_request_clock = (struct timerequest *)CreateIORequest(my_time_port_clock,sizeof(struct timerequest)))
  372.         {
  373.         if(!OpenDevice("timer.device",UNIT_WAITUNTIL,my_time_request_clock,NULL))
  374.         {
  375.             if(notifyrequest = (struct NotifyRequest *)pAllocVec(sizeof(struct NotifyRequest)))
  376.             {
  377.             if ((not_sig = AllocSignal(-1L)) != -1)
  378.             {
  379.                 notifyrequest->nr_Name                          = "ENV:Sys/WBPattern.prefs";
  380.                 notifyrequest->nr_Flags                         = NRF_SEND_SIGNAL;
  381.                 notifyrequest->nr_stuff.nr_Signal.nr_Task       = (struct Task *) FindTask(NULL);
  382.                 notifyrequest->nr_stuff.nr_Signal.nr_SignalNum  = not_sig;
  383.                 if((StartNotify(notifyrequest))==DOSTRUE)
  384.                 {
  385.                 init_time_request(my_time_request_clock,my_time_mask_clock);
  386.                 while(running)
  387.                 {
  388.                     sigs = Wait( my_noti_port_mask | my_test_port_mask | window_mask | my_time_mask_clock | (1L << not_sig) | cxsigflag | my_app_port_mask );
  389.                     if(!closed)
  390.                     {
  391.                     if (sigs & my_time_mask_clock)
  392.                     {
  393.                         WaitIO(my_time_request_clock);
  394.                         init_time_request(my_time_request_clock,my_time_mask_clock);
  395.                         do_what=do_clock;
  396.                         mem_val++;
  397.                         if(mem_val>=set->mem_refresh)
  398.                         {
  399.                         mem_val=0;
  400.                         do_what=do_mem;
  401.                         }
  402.                         vol_val++;
  403.                         if(vol_val>=set->vol_refresh)
  404.                         {
  405.                         vol_val=0;
  406.                         do_what=do_vol;
  407.                         }
  408.                         for(i=0,many=data->list;i<data->num_of_gaug;i++,many=many->next)
  409.                         {
  410.                         if(data->gdg[i])                                     
  411.                         switch (do_what)
  412.                         {
  413.                             case    do_vol:
  414.                                 if(many->type==typ_volume)
  415.                                 {
  416.                                 DoMethod(data->gdg[i],MY_REFRESH,data->win,NULL);
  417.                                 break;
  418.                                 }
  419.                             case    do_mem:
  420.                                 if((many->type!=typ_none)&&(many->type!=typ_iconlauncher)&&(many->type!=typ_simplelauncher)&&(many->type!=typ_volume))
  421.                                 {
  422.                                 DoMethod(data->gdg[i],MY_REFRESH,data->win,NULL);
  423.                                 break;
  424.                                 }
  425.                             default:
  426.                                 if(many->type==typ_clock_) DoMethod(data->gdg[i],MY_REFRESH,data->win,NULL);
  427.                                 break;
  428.                         }
  429.                         }
  430.                         if(first_run){setBase(data);first_run=FALSE;}
  431.                         if(set->win_backfront==win_front) if(data->win->WLayer!=data->scr->LayerInfo.top_layer) WindowToFront(data->win);
  432.                     }
  433.                     if (sigs & my_app_port_mask)
  434.                     {
  435.                         struct AppMessage *appmsg;
  436.                         while(appmsg=(struct AppMessage *)GetMsg( data->appport))
  437.                         {
  438.                         if(appmsg->am_Type=AMTYPE_APPWINDOW)
  439.                         {
  440.                             for(i=0,many=data->list;i<data->num_of_gaug;i++,many=many->next)
  441.                             {
  442.                             if((many->type==typ_simplelauncher)||(many->type==typ_iconlauncher))
  443.                             if(data->gdg[i])
  444.                             {
  445.                                 if((data->gdg[i]->TopEdge <appmsg->am_MouseY)&&((data->gdg[i]->TopEdge +data->gdg[i]->Height)>appmsg->am_MouseY)&&
  446.                                    (data->gdg[i]->LeftEdge<appmsg->am_MouseX)&&((data->gdg[i]->LeftEdge+data->gdg[i]->Width) >appmsg->am_MouseX)
  447.                                 )
  448.                                 {
  449.                                 if(data->gdg[i]->GadgetID<0xFFF0)
  450.                                 {
  451.                                     struct lau_entry    *entry;
  452.                                     GetAttr(LAU_List,(Object *)data->gdg[i],&entry);
  453.                                     if(many->type==typ_simplelauncher)
  454.                                     {
  455.                                     if(entry->next) handle_launcher (data,(UWORD)data->gdg[i]->GadgetID,(struct Gadget *)data->gdg[i],appmsg->am_ArgList,appmsg->am_NumArgs);
  456.                                     else            RunFile         (entry,data,appmsg->am_ArgList,appmsg->am_NumArgs);
  457.                                     }
  458.                                     else
  459.                                     {
  460.                                     ULONG               fullness;
  461.                                     struct BitMapHeader *bmhd;
  462.                                     WORD                x=appmsg->am_MouseX-data->gdg[i]->LeftEdge;
  463.                                     GetAttr(LAU_XPos,(Object *)data->gdg[i],&fullness);
  464.                                     if(entry)
  465.                                     {
  466.                                         do
  467.                                         {
  468.                                         if(entry->img)
  469.                                         {
  470.                                             GetDTAttrs(entry->img,PDTA_BitMapHeader,&bmhd,TAG_DONE);
  471.                                             if(bmhd)
  472.                                             {
  473.                                             if(((fullness+bmhd->bmh_Width)>x)&&(fullness<x)) break;
  474.                                             fullness+=bmhd->bmh_Width;
  475.                                             }
  476.                                         }
  477.                                         }
  478.                                         while(entry=entry->next);
  479.                                         RunFile(entry,data,appmsg->am_ArgList,appmsg->am_NumArgs);
  480.                                     }
  481.                                     }
  482.                                 }
  483.                                 }
  484.                             }
  485.                             }
  486.                         }
  487.                         ReplyMsg(appmsg);
  488.                         }
  489.                     }
  490.                     if (sigs & window_mask)
  491.                     {
  492.                         while(m=(struct IntuiMessage *)GetMsg( data->win->UserPort ))
  493.                         {
  494.                         switch ( m->Class )
  495.                         {
  496.                             case    IDCMP_GADGETDOWN:
  497.                                 {
  498.                                 WORD    x,y;
  499.                                 struct Gadget *g=((struct Gadget *)(m->IAddress));
  500.                                 x=m->MouseX-g->LeftEdge;
  501.                                 y=m->MouseY-g->TopEdge;
  502.                                 ReplyMsg(m);
  503.                                 if(g->GadgetID<0xFFF0)
  504.                                 {
  505.                                     struct lau_entry    *entry;
  506.                                     ULONG               type;
  507.                                     GetAttr(LAU_List,(Object *)g,&entry);
  508.                                     GetAttr(LAU_Type,g,&type);
  509.                                     if(type==typ_iconlauncher)
  510.                                     {
  511.                                     ULONG   fullness;
  512.                                     struct  BitMapHeader *bmhd;
  513.                                     GetAttr(LAU_XPos,(Object *)g,&fullness);
  514.                                     if(entry)
  515.                                     {
  516.                                         do
  517.                                         {
  518.                                         if(entry->img)
  519.                                         {
  520.                                             GetDTAttrs(entry->img,PDTA_BitMapHeader,&bmhd,TAG_DONE);
  521.                                             if(bmhd)
  522.                                             {
  523.                                             if((x<(fullness+bmhd->bmh_Width))&&(x>fullness)) break;
  524.                                             fullness+=bmhd->bmh_Width;
  525.                                             }
  526.                                         }
  527.                                         }
  528.                                         while(entry=entry->next);
  529.                                         RunFile(entry,data,NULL,NULL);
  530.                                     }
  531.                                     }
  532.                                     else if(entry->next)  handle_launcher(data,(UWORD)g->GadgetID,(struct Gadget *)g,NULL,NULL);
  533.                                     else                  RunFile(entry,data,NULL,NULL);
  534.                                 }
  535.                                 }
  536.                                 break;
  537.                             case    IDCMP_CHANGEWINDOW:
  538.                                 ReplyMsg( m );
  539.                                 if(set->bg_type==bg_snap) window_mask=snapSub(set,data);
  540.                                 break;
  541.                             case    IDCMP_CLOSEWINDOW:
  542.                                 running=FALSE;
  543.                                 ReplyMsg( m );
  544.                                 break;
  545.                             case    IDCMP_NEWSIZE:
  546.                                 ReplyMsg( m );
  547.                                 new_window_size(set,data);
  548.                                 set->x_siz=data->win->Width;
  549.                                 data->gauge_x_size=(set->x_siz-(set->win_border_x<<1)-((set->colums-1)*set->win_space_x))/set->colums;
  550.                                 if(set->bg_type==bg_file) fileBackground(set,data);
  551.                                 drawBackground(set,data);
  552.                                 for(i=0,many=data->list;i<data->num_of_gaug;i++,many=many->next) if(data->gdg[i]) SetAttrs(data->gdg[i],GA_Left,set->win_border_x+((i)%set->colums)*data->gauge_x_size+((i)%set->colums)*set->win_space_x,GA_Width,data->gauge_x_size,TAG_DONE);
  553.                                 if(set->bg_type!=bg_snap)RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  554.                                 if(set->bg_type==bg_snap)window_mask=snapSub(set,data);
  555.                                 break;
  556.                             case    IDCMP_VANILLAKEY:
  557.                                 {
  558.                                 int Code=m->Code;
  559.                                 ReplyMsg( m );
  560.                                 switch(Code)
  561.                                 {
  562.                                     case    'S':
  563.                                     case    's':
  564.                                         {
  565.                                         BPTR my_file,my_file1;
  566.                                         set->x_pos=data->win->LeftEdge;
  567.                                         set->y_pos=data->win->TopEdge;
  568.                                         set->x_siz=data->win->Width;
  569.                                         my_file= (BPTR)Open("ENV:TinyMeter",   MODE_NEWFILE);
  570.                                         my_file1=(BPTR)Open("ENVARC:TinyMeter",MODE_NEWFILE);
  571.                                         if(my_file) Write(my_file, set,(ULONG) sizeof(struct tm_sys_set));
  572.                                         if(my_file1)Write(my_file1,set,(ULONG) sizeof(struct tm_sys_set));
  573.                                         many=data->list;
  574.                                         for(i=0;i<data->num_of_gaug;i++)
  575.                                         {
  576.                                             if(my_file) Write(my_file, many,(ULONG) sizeof(struct tm_gau_set));
  577.                                             if(my_file1)Write(my_file1,many,(ULONG) sizeof(struct tm_gau_set));
  578.                                             many=many->next;
  579.                                         }
  580.                                         if(my_file) Close(my_file1);
  581.                                         if(my_file1)Close(my_file);
  582.                                         }
  583.                                         break;
  584.                                     case    'F':
  585.                                     case    'f':
  586.                                         {
  587.                                         ULONG   my_mem;
  588.                                         Forbid();
  589.                                         my_mem=AllocVec(2000000000L,MEMF_PUBLIC);
  590.                                         if(my_mem)FreeVec(my_mem);
  591.                                         Permit();
  592.                                         }
  593.                                         break;
  594.                                     case    'Q':
  595.                                     case    'q':
  596.                                         running=FALSE;
  597.                                         break;
  598.                                     case    'b':
  599.                                     case    'B':
  600.                                         if(set->bg_type==bg_snap)window_mask=snapSub(set,data);
  601.                                         break;
  602.                                 }
  603.                                 }
  604.                                 break;
  605.                             case    IDCMP_MOUSEBUTTONS:
  606.                                 if((m->Code&129)==1) setBase(data);
  607.                             default :
  608.                                 ReplyMsg( m );
  609.                                 break;
  610.                         }
  611.                         }
  612.                     }
  613.                     if (sigs & (1L << not_sig))
  614.                     {
  615.                         Delay(100L);
  616.                         if(set->bg_type==bg_snap) window_mask=snapSub(set,data);
  617.                     }
  618.                     }
  619.                     else if (sigs & my_time_mask_clock) init_time_request(my_time_request_clock,my_time_mask_clock);
  620.  
  621.                     if (sigs & cxsigflag)
  622.                     {
  623.                     CxMsg *msg;
  624.                     ULONG msgid, msgtype;
  625.  
  626.                     while(msg = (CxMsg *)GetMsg(broker_mp))
  627.                     {
  628.                         msgid   = CxMsgID(msg);
  629.                         msgtype = CxMsgType(msg);
  630.                         ReplyMsg((struct Message *)msg);
  631.                         if(msgtype==CXM_COMMAND)
  632.                         {
  633.                         switch(msgid)
  634.                         {
  635.                             case    CXCMD_DISABLE:
  636.                                 {
  637.                                 BOOL pause=TRUE;
  638.                                 ActivateCxObj(broker, 0L);
  639.                                 while(pause)
  640.                                 {
  641.                                     Wait(cxsigflag);
  642.                                     while(msg = (CxMsg *)GetMsg(broker_mp))
  643.                                     {
  644.                                     msgid = CxMsgID(msg);
  645.                                     msgtype = CxMsgType(msg);
  646.                                     ReplyMsg((struct Message *)msg);
  647.                                     if(msgtype==CXM_COMMAND) if(msgid==CXCMD_ENABLE) pause=FALSE;
  648.                                     }
  649.                                 }
  650.                                 ActivateCxObj(broker, 1L);
  651.                                 }
  652.                                 break;
  653.                             case    CXCMD_KILL:
  654.                                 running=FALSE;
  655.                             case    CXCMD_ENABLE:
  656.                                 ActivateCxObj(broker, 1L);
  657.                             default:
  658.                                 break;
  659.                         }
  660.                         }
  661.                     }
  662.                     }
  663.                     if ((sigs & my_test_port_mask)&&(!closed))
  664.                     {
  665.                     while(test_msg=(struct TestMessage *)GetMsg(my_test_port))
  666.                     {
  667.                         switch (test_msg->MethodID)
  668.                         {
  669.                         case    test_test:
  670.                             if(test_msg->set && test_msg->list)
  671.                             {
  672.                                 struct tm_gau_set *manyn,*nextn;
  673.                                 closeWindow(set,data);
  674.                                 first_run=TRUE;
  675.                                 pFreeVec(set);
  676.                                 many=data->list;
  677.                                 do
  678.                                 {
  679.                                 next=many->next;
  680.                                 pFreeVec(many);
  681.                                 }
  682.                                 while(many=next);
  683.  
  684.                                 if(set=(struct tm_sys_set *)pAllocVec(sizeof(struct tm_sys_set)))
  685.                                 {
  686.                                 CopyMem(test_msg->set,set,sizeof(struct tm_sys_set));
  687.                                 }
  688.                                 else exit(0);
  689.  
  690.                                 data->num_of_gaug   = getNum(test_msg->list);
  691.                                 many                = test_msg->list;
  692.                                 if(!(nextn=(struct tm_gau_set *)pAllocVec(sizeof(struct tm_gau_set))))exit(0);
  693.                                 data->list          = nextn;
  694.  
  695.                                 for(i=0;i<data->num_of_gaug;i++)
  696.                                 {
  697.                                 manyn=nextn;
  698.                                 if(!(nextn=(struct tm_gau_set *)pAllocVec(sizeof(struct tm_gau_set))))exit(0);
  699.                                 CopyMem(many,manyn,sizeof(struct tm_gau_set));
  700.                                 manyn->next=nextn;
  701.                                 many=many->next;
  702.                                 }
  703.                                 pFreeVec(nextn);
  704.                                 manyn->next=NULL;
  705.                                 if(openWindow(set,data,gclass,lclass))
  706.                                 {
  707.                                 window_mask  = 1L << data->win->UserPort->mp_SigBit;
  708.                                 }
  709.                                 else running=FALSE;
  710.                                 setBase(data);
  711.                             }
  712.                             break;
  713.                         case    test_getwin:
  714.                             test_msg->posx=data->win->LeftEdge;
  715.                             test_msg->posy=data->win->TopEdge;
  716.                             test_msg->sizx=data->win->Width;
  717.                             break;
  718.                         }
  719.                         ReplyMsg(test_msg);
  720.                     }
  721.                     }
  722.                     if(data->scrnot)
  723.                     {
  724.                     if (sigs & my_noti_port_mask)
  725.                     {
  726.                         struct ScreenNotifyMessage  *snm;
  727.                         while(snm = (struct ScreenNotifyMessage *) GetMsg(my_noti_port))
  728.                         {
  729.                         switch(snm->snm_Type)
  730.                         {
  731.                             case    SCREENNOTIFY_TYPE_CLOSESCREEN:
  732.                                 running=FALSE;
  733.                                 break;
  734.                             case    SCREENNOTIFY_TYPE_WORKBENCH:
  735.                                 if((ULONG)snm->snm_Value)
  736.                                 {
  737.                                 if(closed)
  738.                                 {
  739.                                     Delay(50L);
  740.                                     if(openWindow(set,data,gclass,lclass))
  741.                                     {
  742.                                     window_mask  = 1L << data->win->UserPort->mp_SigBit;
  743.                                     closed=FALSE;
  744.                                     }
  745.                                     else running=FALSE;
  746.                                     setBase(data);
  747.                                 }
  748.                                 }
  749.                                 else
  750.                                 {
  751.                                 if(!closed)
  752.                                 {
  753.                                     closeWindow(set,data);
  754.                                     closed=TRUE;
  755.                                 }
  756.                                 first_run=TRUE;
  757.                                 }
  758.                                 break;
  759.                         }
  760.                         ReplyMsg((struct Message *) snm);
  761.                         }
  762.                     }
  763.                     Delay(10L);
  764.                     }
  765.                 }
  766.                 EndNotify(notifyrequest);
  767.                 }
  768.                 else show(err_nosta);
  769.                 FreeSignal(not_sig);
  770.             }
  771.             else show(err_nosta);
  772.             pFreeVec(notifyrequest);
  773.             }
  774.             else show(err_nomem);
  775.             if(!CheckIO(my_time_request_clock))
  776.             AbortIO(my_time_request_clock);
  777.             WaitIO(my_time_request_clock);
  778.             CloseDevice(my_time_request_clock);
  779.         }
  780.         else show(err_nodev);
  781.         DeleteIORequest(my_time_request_clock);
  782.         }
  783.         else show(err_nopor);
  784.         DeleteMsgPort(my_time_port_clock);
  785.     }
  786.     else show(err_nopor);
  787.     DeletePort(my_test_port);
  788.     }
  789.     else show(err_nopor);
  790.     if(data->scrnot)
  791.     {
  792.     if((!data->on_public)|(!strcmp(&set->pub_name[0],"Workbench")))
  793.         while(!RemWorkbenchClient(my_handler)) Delay(10);
  794.     else
  795.         while(!RemCloseScreenClient(my_handler)) Delay(10);
  796.     DeleteMsgPort(my_noti_port);
  797.     }
  798.     return(set);
  799. }
  800.  
  801.